package com.java.awt.observer;

import java.util.Observable;
import java.util.Observer;

class BeingWatched extends Observable{
	void counter(int number){
		for(; number>=0; number--){
			this.setChanged();
			this.notifyObservers(number);
		}
	}
}
class Watcher1 implements Observer{
	public void update(Observable o,Object obj){
		System.out.println("Watcher1 count is: "+ obj);
	}
}
class Watcher2 implements Observer{
	public void update(Observable o,Object obj){
		if((Integer)obj <= 5){
			System.out.println("Watcher2 count is: "+ obj);
		}
	} 
}
public class TwoObservers {
	public static void main(String[] args) {
		BeingWatched watched = new BeingWatched();
		Watcher1 w1 = new Watcher1();
		Watcher2 w2 = new Watcher2();
		watched.addObserver(w1);
		watched.addObserver(w2);
		watched.counter(10);
	}
}
